package com.itheima.listdemo;

import java.util.ArrayList;

public class ArrayListDemo1 {
    public static void main(String[] args) {
        //ArrayList的学习

        //创建集合对象
        ArrayList<String> list=new ArrayList<>();
        System.out.println(list);//[]

        //添加元素 Boolean add()
        list.add("aaa");
        System.out.println(list.add("aaa"));//true
        System.out.println(list);//[aaa]
        list.add("bbb");
        System.out.println(list);//[aaa, bbb]
        list.add("ccc");
        list.add("ddd");

        //删除元素 Boolean remove()
        list.remove(0);
        System.out.println(list.remove(0));//aaa
        System.out.println(list);
        list.remove("bbb");
        System.out.println(list.remove("bbb"));
        System.out.println(list);

        //修改元素 String set(int index, String element)
        list.set(1,"eee");
        System.out.println(list.set(1,"eee"));//bbb
        System.out.println(list);

        //查询元素 String get(int index)
        System.out.println(list.get(1));//eee

        //遍历集合 int size()
        for (int i = 0; i < list.size(); i++) {
            System.out.println(list.get(i));;
        }

    }
}
